package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderVO;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author: WangHongKun
 * @Date: 2022/9/22 16:58
 * @Email: 2028911483@qq.com
 * @Phone: 18683977706
 */

@Mapper
public interface OrderMapper {

    void insert(Orders orders);

    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    void update(Orders orders);

    List<Orders>  getByUserIdAndStatus(Orders orders);

    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select * from orders where  id =#{id}")
    Orders  getById(Long id);

    @Update("update orders set status =#{status} where id=#{id} ")
    void cancel(Long id ,Integer status);

    @Update("update orders set status =#{status} where id=#{id} ")
    void setOrderStatus(Long id ,Integer status);


    Integer  getStatusCount(Integer status);


    @Select(" select * from orders where status = #{status} and order_time < #{time}")
    List<Orders>  getByStatusAndTime(Integer status, LocalDateTime  time);

    @Select("select  * from orders where  status =#{status}")
    List<Orders>  getByStatus(Integer status);


    Double getSumByStatusAndTime(Integer status, LocalDateTime begin,LocalDateTime end);


    Integer getEveryDayOrders(LocalDateTime begin,LocalDateTime end);

    Integer getEveryValidDayOrders(Integer status,LocalDateTime begin,LocalDateTime end);


}
